<template>
  <div class="app-container">
    <!--  -->
    <!-- 统计卡片 -->
    <div class="stats-container">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="stat-card total-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-user"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ total }}</div>
                <div class="stat-label">总客户数</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card claimed-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-check"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ claimedCount }}</div>
                <div class="stat-label">已认领</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card urgent-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-warning"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ urgentCount }}</div>
                <div class="stat-label">紧急项目</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card followed-card" shadow="hover">
            <div class="stat-content">
              <div class="stat-icon">
                <i class="el-icon-time"></i>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ followedCount + completedCount }}</div>
                <div class="stat-label">已跟进/已完成</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 搜索卡片 -->
    <el-card class="search-card" shadow="hover">
      <div slot="header" class="card-header">
        <span class="card-title">
          <i class="el-icon-search"></i>
          搜索条件
        </span>
        <div class="header-actions">
          <el-button type="text" @click="toggleSearch">
            {{ showSearch ? '收起' : '展开' }}
            <i :class="showSearch ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
          </el-button>
          <el-button type="text" @click="resetQuery" icon="el-icon-refresh">重置</el-button>
        </div>
      </div>
      
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="客户名称" prop="customerName">
              <el-input
                v-model="queryParams.customerName"
                placeholder="请输入客户名称"
                clearable
                @keyup.enter.native="handleQuery"
                prefix-icon="el-icon-office-building"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input
                v-model="queryParams.contactPhone"
                placeholder="请输入联系电话"
                clearable
                @keyup.enter.native="handleQuery"
                prefix-icon="el-icon-phone"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户来源" prop="source">
              <el-select
                v-model="queryParams.source"
                placeholder="请选择来源"
                clearable
                style="width: 100%"
              >
                <el-option label="拓客来源" value="0"></el-option>
                <el-option label="个人来源" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目紧急程度" prop="urgencyLevel">
              <el-select
                v-model="queryParams.urgencyLevel"
                placeholder="请选择项目紧急程度"
                clearable
                style="width: 100%"
              >
                <el-option label="一般" value="一般"></el-option>
                <el-option label="紧急" value="紧急"></el-option>
                <el-option label="特急" value="特急"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="认领人" prop="claimPerson">
              <el-input
                v-model="queryParams.claimPerson"
                placeholder="请输入认领人"
                clearable
                @keyup.enter.native="handleQuery"
                prefix-icon="el-icon-user"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="认领状态" prop="claimStatus">
              <el-select
                v-model="queryParams.claimStatus"
                placeholder="请选择认领状态"
                clearable
                style="width: 100%"
              >
                <el-option label="已认领" :value="0"></el-option>
                <el-option label="未认领" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="跟进状态" prop="followStatus">
              <el-select
                v-model="queryParams.followStatus"
                placeholder="请选择跟进状态"
                clearable
                style="width: 100%"
              >
                <el-option label="已跟进" :value="0"></el-option>
                <el-option label="未跟进" :value="1"></el-option>
                <el-option label="已完成" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <!-- 操作按钮卡片 -->
    <el-card class="action-card" shadow="hover">
      <div class="action-buttons">
        <div class="left-buttons">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['customer:customer_info:add']"
          >新增客户</el-button>
          <el-button
            type="success"
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['customer:customer_info:edit']"
          >修改</el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['customer:customer_info:remove']"
          >删除</el-button>
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['customer:customer_info:export']"
          >导出</el-button>
        </div>
        <div class="right-buttons">
          <el-button
            type="info"
            icon="el-icon-view"
            size="mini"
            @click="handleView"
            :disabled="single"
          >查看详情</el-button>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </div>
      </div>
    </el-card>

    <!-- 数据展示卡片 -->
    <el-card class="data-card" shadow="hover">
      <div slot="header" class="card-header">
        <span class="card-title">
          <i class="el-icon-user"></i>
          客户认领跟进列表
        </span>
        <span class="card-subtitle">共 {{ total }} 条记录</span>
      </div>

      <el-table 
        v-loading="loading" 
        :data="customer_infoList" 
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
        stripe
        border
        class="custom-table"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="selection" width="55" align="center" />
        
        <el-table-column label="客户名称" align="center" prop="customerName" min-width="150" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="customer-name">
              <i class="el-icon-office-building"></i>
              <span>{{ scope.row.customerName }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" prop="contactPerson" min-width="100">
          <template slot-scope="scope">
            <div class="contact-person">
              <i class="el-icon-user"></i>
              <span>{{ scope.row.contactPerson }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="联系电话" align="center" prop="contactPhone" min-width="130">
          <template slot-scope="scope">
            <div class="contact-phone">
              <i class="el-icon-phone"></i>
              <span>{{ scope.row.contactPhone }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="客户来源" align="center" prop="source" min-width="100">
          <template slot-scope="scope">
            <el-tag 
              type="info" 
              size="mini"
              effect="plain"
            >
              <i class="el-icon-connection"></i>
              {{ scope.row.source === 0 ? '拓客来源' : '个人来源' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="项目紧急程度" align="center" prop="urgencyLevel" min-width="120">
          <template slot-scope="scope">
            <el-tag 
              :type="getUrgencyType(scope.row.urgencyLevel)"
              size="mini"
              effect="dark"
            >
              <i :class="getUrgencyIcon(scope.row.urgencyLevel)"></i>
              {{ scope.row.urgencyLevel }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="认领日期" align="center" prop="claimDate" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.claimDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="认领人" align="center" prop="claimPerson" min-width="100" />
        <el-table-column label="认领状态" align="center" prop="claimStatus" min-width="100">
          <template slot-scope="scope">
            <el-tag :type="scope.row.claimStatus === 0 ? 'success' : 'danger'" size="mini" effect="dark">
              <i :class="scope.row.claimStatus === 0 ? 'el-icon-check' : 'el-icon-close'"></i>
              {{ scope.row.claimStatus === 0 ? '已认领' : '未认领' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="跟进状态" align="center" prop="followStatus" min-width="100">
          <template slot-scope="scope">
            <el-tag :type="getFollowStatusType(scope.row.followStatus)" size="mini" effect="dark">
              <i :class="getFollowStatusIcon(scope.row.followStatus)"></i>
              {{ getFollowStatusText(scope.row.followStatus) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="跟进天数" align="center" prop="followDays" min-width="100" />
        <el-table-column label="操作日期" align="center" prop="operationDate" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.operationDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户分类" align="center" prop="customerClass" min-width="100" />
        <el-table-column label="所在-省" align="center" prop="province" min-width="100" />
        <el-table-column label="所在-市" align="center" prop="city" min-width="100" />
        <el-table-column label="行业" align="center" prop="industry" min-width="100" show-overflow-tooltip />
        <el-table-column label="备注" align="center" prop="remark" min-width="150" show-overflow-tooltip />
        
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['customer:customer_info:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['customer:customer_info:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改客户认领跟进对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-tabs v-model="activeTab" type="border-card">
          <el-tab-pane label="基本信息" name="basic">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="客户名称" prop="customerName">
                  <el-input v-model="form.customerName" placeholder="请输入客户名称" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系人" prop="contactPerson">
                  <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="联系电话" prop="contactPhone">
                  <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="其他联络方式" prop="otherContact">
                  <el-input v-model="form.otherContact" placeholder="请输入其他联络方式" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="来源" prop="source">
                  <el-select v-model="form.source" placeholder="请选择来源" style="width: 100%">
                    <el-option label="拓客来源" :value="0" />
                    <el-option label="个人来源" :value="1" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="项目紧急程度" prop="urgencyLevel">
                  <el-select
                    v-model="form.urgencyLevel"
                    placeholder="请选择项目紧急程度"
                    style="width: 100%"
                  >
                    <el-option label="一般" value="一般"></el-option>
                    <el-option label="紧急" value="紧急"></el-option>
                    <el-option label="特急" value="特急"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
          
          <el-tab-pane label="地址信息" name="address">
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="详细地址" prop="address">
                  <el-input v-model="form.address" placeholder="请输入地址" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="所在-省" prop="province">
                  <el-input v-model="form.province" placeholder="请输入所在省份" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="所在-市" prop="city">
                  <el-input v-model="form.city" placeholder="请输入所在城市" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="行业" prop="industry">
                  <el-input v-model="form.industry" placeholder="请输入行业" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="客户分类" prop="customerClass">
                  <el-input v-model="form.customerClass" placeholder="请输入客户分类" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
          
          <el-tab-pane label="认领信息" name="claim">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="认领日期" prop="claimDate">
                  <el-date-picker 
                    clearable
                    v-model="form.claimDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择认领日期"
                    style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="认领人" prop="claimPerson">
                  <el-input v-model="form.claimPerson" placeholder="请输入认领人" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="认领状态" prop="claimStatus">
                  <el-select v-model="form.claimStatus" placeholder="请选择认领状态" style="width: 100%">
                    <el-option label="已认领" :value="0"></el-option>
                    <el-option label="未认领" :value="1"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="操作日期" prop="operationDate">
                  <el-date-picker 
                    clearable
                    v-model="form.operationDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择操作日期"
                    style="width: 100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
          
          <el-tab-pane label="跟进信息" name="follow">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="跟进状态" prop="followStatus">
                  <el-select v-model="form.followStatus" placeholder="请选择跟进状态" style="width: 100%">
                    <el-option label="已跟进" :value="0"></el-option>
                    <el-option label="未跟进" :value="1"></el-option>
                    <el-option label="已完成" :value="2"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="跟进天数" prop="followDays">
                  <el-input v-model="form.followDays" placeholder="请输入跟进天数" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input 
                    v-model="form.remark" 
                    type="textarea" 
                    :rows="4"
                    placeholder="请输入备注信息" 
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看详情对话框 -->
    <el-dialog title="客户详情" :visible.sync="viewOpen" width="800px" append-to-body>
      <div class="customer-detail">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="客户公司名称">{{ viewForm.customerName }}</el-descriptions-item>
          <el-descriptions-item label="联系人">{{ viewForm.contactPerson }}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{ viewForm.contactPhone }}</el-descriptions-item>
          <el-descriptions-item label="其他联络方式">{{ viewForm.otherContact }}</el-descriptions-item>
          <el-descriptions-item label="客户来源">
            <el-tag :type="viewForm.source === 0 ? 'info' : 'warning'" size="mini">
              {{ viewForm.source === 0 ? '拓客来源' : '个人来源' }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="项目紧急程度">
            <el-tag :type="getUrgencyType(viewForm.urgencyLevel)" size="mini">
              {{ viewForm.urgencyLevel }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="认领日期">{{ parseTime(viewForm.claimDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="认领人">{{ viewForm.claimPerson }}</el-descriptions-item>
          <el-descriptions-item label="认领状态">
            <el-tag :type="viewForm.claimStatus === 0 ? 'success' : 'danger'" size="mini">
              {{ viewForm.claimStatus === 0 ? '已认领' : '未认领' }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="跟进状态">
            <el-tag :type="getFollowStatusType(viewForm.followStatus)" size="mini">
              {{ getFollowStatusText(viewForm.followStatus) }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="跟进天数">{{ viewForm.followDays }}</el-descriptions-item>
          <el-descriptions-item label="操作日期">{{ parseTime(viewForm.operationDate, '{y}-{m}-{d}') }}</el-descriptions-item>
          <el-descriptions-item label="客户分类">{{ viewForm.customerClass }}</el-descriptions-item>
          <el-descriptions-item label="所在-省">{{ viewForm.province }}</el-descriptions-item>
          <el-descriptions-item label="所在-市">{{ viewForm.city }}</el-descriptions-item>
          <el-descriptions-item label="行业">{{ viewForm.industry }}</el-descriptions-item>
          <el-descriptions-item label="详细地址" :span="2">{{ viewForm.address }}</el-descriptions-item>
          <el-descriptions-item label="备注" :span="2">{{ viewForm.remark }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCustomer_info, getCustomer_info, delCustomer_info, addCustomer_info, updateCustomer_info } from "@/api/customer/customer_info"

export default {
  name: "Customer_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户认领跟进表格数据
      customer_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示查看详情弹出层
      viewOpen: false,
      // 当前激活的标签页
      activeTab: 'basic',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        source: null,
        customerName: null,
        contactPhone: null,
        claimPerson: null,
        claimStatus: null,
        followStatus: null,
        customerClass: null,
        urgencyLevel: null,
        province: null,
        city: null,
      },
      // 统计数据
      claimedCount: 0,
      urgentCount: 0,
      followedCount: 0,
      completedCount: 0,
      // 表单参数
      form: {},
      // 查看详情表单参数
      viewForm: {},
      // 表单校验
      rules: {
        source: [
          { required: true, message: "来源不能为空", trigger: "blur" }
        ],
        customerName: [
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        followStatus: [
          { required: true, message: "跟进状态不能为空", trigger: "change" }
        ],
        urgencyLevel: [
          { required: true, message: "项目紧急程度不能为空", trigger: "blur" }
        ],
        claimStatus: [
          { required: true, message: "认领状态不能为空", trigger: "change" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询客户认领跟进列表 */
    getList() {
      this.loading = true
      listCustomer_info(this.queryParams).then(response => {
        this.customer_infoList = response.rows
        this.total = response.total
        this.calculateStats()
        this.loading = false
      })
    },
    /** 计算统计数据 */
    calculateStats() {
      this.claimedCount = this.customer_infoList.filter(item => item.claimStatus === 0).length
      this.urgentCount = this.customer_infoList.filter(item => 
        item.urgencyLevel === '紧急' || item.urgencyLevel === '特急'
      ).length
      this.followedCount = this.customer_infoList.filter(item => item.followStatus === 0).length
      this.completedCount = this.customer_infoList.filter(item => item.followStatus === 2).length
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        source: null,
        claimDate: null,
        customerName: null,
        contactPerson: null,
        contactPhone: null,
        otherContact: null,
        address: null,
        claimPerson: null,
        claimStatus: null,
        followStatus: null,
        followDays: null,
        operationDate: null,
        customerClass: null,
        urgencyLevel: null,
        province: null,
        city: null,
        industry: null,
        remark: null
      }
      this.resetForm("form")
      this.activeTab = 'basic'
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加客户认领跟进"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCustomer_info(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改客户认领跟进"
      })
    },
    /** 查看详情按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      getCustomer_info(id).then(response => {
        this.viewForm = response.data
        this.viewOpen = true
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addCustomer_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除客户认领跟进编号为"' + ids + '"的数据项？').then(function() {
        return delCustomer_info(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customer/customer_info/export', {
        ...this.queryParams
      }, `customer_info_${new Date().getTime()}.xlsx`)
    },
    /** 切换搜索显示 */
    toggleSearch() {
      this.showSearch = !this.showSearch
    },
    /** 获取紧急程度标签类型 */
    getUrgencyType(urgency) {
      switch(urgency) {
        case '一般': return 'info'
        case '紧急': return 'warning'
        case '特急': return 'danger'
        default: return 'info'
      }
    },
    /** 获取紧急程度图标 */
    getUrgencyIcon(urgency) {
      switch(urgency) {
        case '一般': return 'el-icon-info'
        case '紧急': return 'el-icon-warning'
        case '特急': return 'el-icon-error'
        default: return 'el-icon-info'
      }
    },
    /** 获取跟进状态标签类型 */
    getFollowStatusType(status) {
      switch(status) {
        case 0: return 'success'
        case 1: return 'warning'
        case 2: return 'info'
        default: return 'info'
      }
    },
    /** 获取跟进状态图标 */
    getFollowStatusIcon(status) {
      switch(status) {
        case 0: return 'el-icon-check'
        case 1: return 'el-icon-time'
        case 2: return 'el-icon-finished'
        default: return 'el-icon-time'
      }
    },
    /** 获取跟进状态文本 */
    getFollowStatusText(status) {
      switch(status) {
        case 0: return '已跟进'
        case 1: return '未跟进'
        case 2: return '已完成'
        default: return '未跟进'
      }
    },
    /** 表格行点击事件 */
    handleRowClick(row, column, event) {
      // 可以在这里添加行点击逻辑
    },
    /** 表格行样式 */
    tableRowClassName({row, rowIndex}) {
      if (row.urgencyLevel === '特急') {
        return 'urgent-row'
      } else if (row.urgencyLevel === '紧急') {
        return 'warning-row'
      }
      return ''
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
}

.stats-container {
  margin-bottom: 20px;
  
  .stat-card {
    border-radius: 12px;
    border: none;
    transition: all 0.3s ease;
    
    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }
    
    .stat-content {
      display: flex;
      align-items: center;
      padding: 10px;
      
      .stat-icon {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 15px;
        
        i {
          font-size: 24px;
          color: white;
        }
      }
      
      .stat-info {
        flex: 1;
        
        .stat-number {
          font-size: 28px;
          font-weight: bold;
          color: #303133;
          line-height: 1;
          margin-bottom: 5px;
        }
        
        .stat-label {
          font-size: 14px;
          color: #909399;
        }
      }
    }
    
    &.total-card .stat-icon {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    
    &.claimed-card .stat-icon {
      background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    }
    
    &.urgent-card .stat-icon {
      background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
    }
    
    &.followed-card .stat-icon {
      background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    }
  }
}

.search-card {
  margin-bottom: 20px;
  border-radius: 12px;
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    
    .card-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;
      
      i {
        margin-right: 8px;
        color: #409eff;
      }
    }
    
    .header-actions {
      display: flex;
      gap: 10px;
    }
  }
}

.action-card {
  margin-bottom: 20px;
  border-radius: 12px;
  
  .action-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    
    .left-buttons, .right-buttons {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
    }
  }
}

.data-card {
  border-radius: 12px;
  
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    
    .card-title {
      font-size: 16px;
      font-weight: 600;
      color: #303133;
      
      i {
        margin-right: 8px;
        color: #409eff;
      }
    }
    
    .card-subtitle {
      font-size: 14px;
      color: #909399;
    }
  }
}

.custom-table {
  border-radius: 8px;
  overflow: hidden;
  
  ::v-deep .el-table__header-wrapper {
    background-color: #fafafa;
  }
  
  ::v-deep .el-table__row {
    transition: all 0.3s ease;
    cursor: pointer;
    
    &:hover {
      background-color: #f5f7fa !important;
    }
    
    &.urgent-row {
      background-color: #fef0f0 !important;
      
      &:hover {
        background-color: #fde2e2 !important;
      }
    }
    
    &.warning-row {
      background-color: #fdf6ec !important;
      
      &:hover {
        background-color: #faecd8 !important;
      }
    }
  }
  
  ::v-deep .el-table__cell {
    padding: 12px 0;
  }
  
  .customer-name, .contact-person, .contact-phone {
    display: flex;
    align-items: center;
    justify-content: center;
    
    i {
      margin-right: 5px;
      color: #409eff;
    }
  }
}

::v-deep .el-card {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: none;
  
  &:hover {
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.15);
  }
}

::v-deep .el-button {
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  
  &.el-button--primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    
    &:hover {
      background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
      transform: translateY(-2px);
    }
  }
  
  &.el-button--success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border: none;
    
    &:hover {
      background: linear-gradient(135deg, #0f8a7d 0%, #2dd66e 100%);
      transform: translateY(-2px);
    }
  }
  
  &.el-button--danger {
    background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
    border: none;
    
    &:hover {
      background: linear-gradient(135deg, #e63a5f 0%, #e64426 100%);
      transform: translateY(-2px);
    }
  }
  
  &.el-button--warning {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    
    &:hover {
      background: linear-gradient(135deg, #d884e2 0%, #d44e5f 100%);
      transform: translateY(-2px);
    }
  }
  
  &.el-button--info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    border: none;
    
    &:hover {
      background: linear-gradient(135deg, #45a1f0 0%, #00e5f0 100%);
      transform: translateY(-2px);
    }
  }
}

::v-deep .el-tag {
  border-radius: 6px;
  font-weight: 500;
  
  &.el-tag--info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
  }
}

::v-deep .el-pagination {
  margin-top: 20px;
  text-align: center;
}

::v-deep .el-dialog {
  border-radius: 12px;
  
  .el-dialog__header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
    
    .el-dialog__title {
      color: white;
      font-weight: 600;
    }
  }
}

::v-deep .el-form-item__label {
  font-weight: 500;
  color: #606266;
}

::v-deep .el-input__inner {
  border-radius: 8px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s ease;
  
  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
}

::v-deep .el-select .el-input__inner {
  border-radius: 8px;
}

::v-deep .el-textarea__inner {
  border-radius: 8px;
  border: 1px solid #dcdfe6;
  transition: all 0.3s ease;
  
  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
}

::v-deep .el-tabs--border-card {
  border-radius: 8px;
  box-shadow: none;
  border: 1px solid #dcdfe6;
}

::v-deep .el-tabs--border-card > .el-tabs__header {
  background-color: #f5f7fa;
  border-bottom: 1px solid #dcdfe6;
}

::v-deep .el-tabs--border-card > .el-tabs__header .el-tabs__item {
  border-radius: 6px 6px 0 0;
  margin-right: 5px;
  
  &.is-active {
    background-color: #409eff;
    color: white;
    border-color: #409eff;
  }
}

.customer-detail {
  padding: 20px 0;
}

::v-deep .el-descriptions {
  .el-descriptions-item__label {
    font-weight: 600;
    color: #606266;
    background-color: #fafafa;
  }
  
  .el-descriptions-item__content {
    color: #303133;
  }
}
</style>
